USE [DSRSystem_Temp]
GO

alter table [dbo].[FinalizedIndicators]
ADD Untickedboxes nvarchar(max) null

alter table [dbo].[StageFinalizedIndicators]
ADD Untickedboxes nvarchar(max) null

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spGetIndicatorsByCompanyIds]
	@CompanyIds NVARCHAR(MAX)
AS
BEGIN
	SET NOCOUNT ON;

	DECLARE @XML XML
	SET @XML = CONVERT(XML, @CompanyIds, 1)

	DECLARE @SelectedCompanies TABLE
	(
		Id uniqueidentifier
	)
	INSERT INTO @SelectedCompanies
	SELECT TID.id.value('.','uniqueidentifier') AS Id
	FROM @XML.nodes('/CompanyIds') AS T(c) outer apply T.c.nodes('Id') as TID(id)

	SELECT FinalizedIndicators.[Id]
		  ,[CompanyId]
		  ,[Name]
		  ,[Number]
		  ,[Description]
		  ,[Score]
		  ,[Outlook]
		  ,[Tickedboxes]
		  ,[Comments]
		  ,[Sources]
		  ,[Untickedboxes]
	FROM [dbo].[FinalizedIndicators] AS FinalizedIndicators
	INNER JOIN @SelectedCompanies AS SelectedCompanies ON SelectedCompanies.Id = FinalizedIndicators.CompanyId
END
